# -*- coding:utf-8 -*-
import time

from selenium.webdriver.common.by import By

from PageClass.common.boeCommon import BoeCommon
from PageClass.ecsPageClass.ecsIndexPage import EcsIndexPage
from Util import logger


class Class_EmployeePrepaymentBoe(EcsIndexPage, BoeCommon):
    # 有可能出现错误提示的元素位置
    _MessageBox = (By.CLASS_NAME, 'el-message__content')
    _accountInputErrorBox = (By.XPATH, '//*[@id="app"]/div/div[1]/div/form/div[1]/div/div')
    _passwordInputErrorBox = (By.XPATH, '//*[@id="app"]/div/div[1]/div/form/div[2]/div/div')

    # 选第一行核销# 提交
    def click_line1(self):
        _line1 = (By.XPATH,
                  '//tbody/tr/td[@class="el-table_3_column_6 is-center "]/div/label/span/span[@class="el-checkbox__inner"]')
        self.click(*_line1)
        time.sleep(1)
        # 提交
        self.click(*(By.XPATH, '//button[@class="el-button el-button--primary el-button--small"]'))

    # 还款明细区-还款方式
    def select_operationSubType(self, text):
        # 点击还款方式
        self.click(*(By.XPATH, '//input[@id="loan.0.operationSubTypeId"]'))
        time.sleep(1)
        # 选择还款方式
        _element = (By.XPATH, f'//div[@class="el-select-dropdown el-popper"]/div/div/ul/li/div/span[text()="{text}"]')
        self.click(*_element)

    # 还款明细区-还款金额
    def input_Money(self, money):
        _money = (By.XPATH, '//div[@id="loan.0.expenseAmount"]')
        self.send_text(money, *_money)
        logger.info("输入还款明细区-还款金额")

    # 还款明细区-收款账号
    def click_account(self):
        _account = (By.XPATH, '//input[@id="loan.0.bankAccount"]')
        self.click(*_account)
        logger.info("点击还款明细区-收款账号")

    # 还款明细区-还款日期
    def select_loanRepaymentDate(self):
        _element = (By.ID, 'loan.0.loanRepaymentDate')
        self.click(*_element)
        time.sleep(1)
        self.select_date(time.strftime('%Y-%m-%d').split('-')[0], time.strftime('%Y-%m-%d').split('-')[1],
                         time.strftime('%Y-%m-%d').split('-')[2])  # 取当天

    # 还款明细区-还款说明
    def input_loanremark(self, text):
        _loanremark = (By.XPATH,
                       '//div[@class="bill-field text placeholder-color"]/div[@class="el-tooltip el-input el-input--mini el-input--suffix"]')
        self.send_text(text, *_loanremark)
        logger.info("输入还款明细区-还款说明")

    # 核销明细区-本次核销金额
    def input_cavAmount(self, prepayment):
        _money = (By.XPATH, '//div[@id="boeExpenseCavDTOs.0.cavAmount"]')
        self.send_text(prepayment, *_money)
        logger.info("输入还款明细区-还款金额")

    BoeSuccessMsg = (By.XPATH, '//*[@id="app"]/div/div/div[4]/div/div/div[2]/div/p')

    def getBoeSuccessMessage(self):
        # 提单成功结果页面提示语
        return self.get_elementText(*self.BoeSuccessMsg)
